package cc.yugu.yhdw.webserver.service.basic;


import cc.yugu.yhdw.common.constant.CacheKey;
import cc.yugu.yhdw.common.domain.basic.AdImage;
import cc.yugu.yhdw.common.domain.basic.Agent;
import cc.yugu.yhdw.webserver.persistence.basic.AdImageMapper;
import com.whalin.MemCached.MemCachedClient;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 代理商业务 切面类
 *
 * @Date:Created in 2018/7/3 11:55
 * @Author:
 * @Modified By: zjn 2018/7/3 11:55
 */
@Component
@Aspect
public class AgentServiceAspect {

    @Autowired
    MemCachedClient memCachedClient;
    // 切点
    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.basic.AgentService.update(..))")
    private void update() {}
    @Around("update()")
    public Object update(ProceedingJoinPoint joinPoint) throws Throwable {
        Agent agent = (Agent) joinPoint.getArgs()[0];
        Object result = joinPoint.proceed();
        // "27:%d"  运营商id 替换运营商前缀 输出
        String key = CacheKey.key(CacheKey.K_ID_V_AGENT_INFO, agent.getId());
        // 根据 key 删除对象
        memCachedClient.delete(key);

        return result;
    }
}
